function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

import localStorage from '../utils/localStorage'; // 是否需要重置数据

var shoudReset = function shoudReset(localList, newList) {
  if (!localList) {
    // 本地没有存储过
    return true;
  }

  if (localList && localList.length !== newList.length) {
    // 新增或者删除了元素
    return true;
  } // 精确比较


  var preListMap = {}; //

  localList.forEach(function (i) {
    // 保存一份以3个为key的 map 保证最大的正确率
    preListMap["".concat(i.label).concat(i.value).concat(i.inputType)] = i;
  });

  for (var i = 0; i < newList.length; i += 1) {
    if (!preListMap["".concat(newList[i].label).concat(newList[i].value).concat(newList[i].inputType)]) {
      return true; // 只要找不到,立马return
    }
  }

  return false;
};

export var getId = function getId() {
  return "setFilter".concat(localStorage.getItem('userId')).concat(window.location.pathname.replace(/\//g, '-'));
};
export var getList = function getList() {
  var preList = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
  var list = localStorage.getItem(getId()) && JSON.parse(localStorage.getItem(getId()));
  var preListMap = {}; //

  preList.forEach(function (i) {
    // 保存一份以3个为key的 map 保证最大的正确率
    preListMap["".concat(i.label).concat(i.value).concat(i.inputType)] = i;
  });

  if (shoudReset(list, preList)) {
    list = preList.map(function (i) {
      var it = i;
      it.show = true; // 全部显示

      return it;
    }); // 存

    localStorage.setItem(getId(), JSON.stringify(list.map(function (i) {
      var it = _objectSpread({}, i); // 删除react元素


      delete it.render;
      delete it.labelRender;
      delete it.listArr; // 该数据太大，不应该存在本地

      return it;
    })));
    return list;
  } else {
    // 为每一项添加 render方法
    list = list.map(function (i) {
      var it = i; // it.render = preListMap[it.label].render;

      return _objectSpread(_objectSpread({}, preListMap["".concat(i.label).concat(i.value).concat(i.inputType)]), {}, {
        show: it.show
      }); // 这样做，本地存储生效的只有，顺序和显示隐藏
    });
    return list;
  }
};